package org.zhao.nettydemos.decoder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @Auther: xiaohui.zhao
 * @Date: 2021/9/16 08:19
 * @Description:
 */
@Slf4j
public class Byte2IntegerDecoder extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
      while (byteBuf.readableBytes()>=4){
          int i = byteBuf.readInt();
          log.info("解码出一个整数 : "+i);
          list.add(i);
      }
    }
}